﻿using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Volo.Abp.Application.Services;

namespace TianShu.WebApi
{
    [Route("api/[controller]")]
    [ApiController]
    [Authorize]
    public class TianShuQueryController<TListDto, TKey> : TianShuQueryController<TListDto, TKey, TListDto>
    {
        IReadOnlyAppService<TListDto, TKey> QueryService;
        public TianShuQueryController(IReadOnlyAppService<TListDto, TKey> queryService):base(queryService)
        {
            this.QueryService = queryService;
        }
    }
    public class TianShuQueryController<TListDto, TKey, TDetailDto> : TianShuController
    {
        IReadOnlyAppService<TDetailDto, TListDto, TKey> QueryService;
        public TianShuQueryController(IReadOnlyAppService<TDetailDto, TListDto, TKey> queryService)
        {
            this.QueryService = queryService;
        }

        [HttpGet("getbyid")]
        public virtual async Task<IActionResult> GetById(TKey id)
        {
            var result = await QueryService.GetAsync(id);
            return Json(result);
        }
        [HttpGet("getbyurl")]
        public virtual async Task<IActionResult> GetByUrl()
        {
            var urlparam = this.Request.Query.GetUrlParams();
            var result = await QueryService.GetUrlParamAsync(urlparam);
            return Json(result);
        }
    }
}
